<template>
  <div class="modal" v-if="localModal" @click="closeModal">
    <div class="content">
      <div style="cursor: pointer;" v-if="showClose">
        <el-icon :size="40" style="margin-bottom: 10px;" @click="closeModal">
          <circle-close />
        </el-icon>
      </div>
      <slot />
    </div>
  </div>
</template>
<script lang="ts" setup>
import { watch } from 'vue';
import { ref } from 'vue'
const props = defineProps({
  showModal: {
    default: false
  },
  closeOnModal: {
    default: true
  },
  showClose: {
    default: true
  }
})
watch(props, () => {
  localModal.value = props.showModal
});

const emit = defineEmits(['update:showModal'])
const localModal = ref(props.showModal)
const closeModal = () => {
  if (props.closeOnModal) {
    localModal.value = false
  }
  emit('update:showModal', localModal.value)
}
</script>
<style lang="scss" scoped>
.modal {
  position: absolute;
  z-index: 10000;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba($color: #5c5c5c, $alpha: .5);
  display: flex;
  flex-direction: column;
  justify-content: center;

  .content {
    margin: 0 auto;
  }
}
</style>